

import java.awt.Dimension;
import java.awt.Font;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class NGuessNumber extends JFrame {
    private JTextField txtGuess;
    private JTextField txtGuess2;
    private JTextField txtGuess3;
    private JTextField txtGuess4;
    private JLabel lblOutput;
    private JLabel lblOutput2;
    private JLabel lblOutput3;
    private JLabel lblOutput4;
    private JButton btnPlayAgain;
    private int ra;
    private int ra2;
    private int ra3;
    private int ra4;

    public void getra() {
        this.ra = (int) (Math.random() * 10.0D) + 1;
        this.ra2 = (int) (Math.random() * 10.0D) + 1;
        this.ra3 = (int) (Math.random() * 10.0D) + 1;
        this.ra4 = (int) (Math.random() * 10.0D) + 1;
    }

    public void getra2() {
        this.ra2 = (int) (Math.random() * 10.0D) + 1;
    }

    public void getra3() {
        this.ra3 = (int) (Math.random() * 10.0D) + 1;
    }

    public void getra4() {
        this.ra4 = (int) (Math.random() * 10.0D) + 1;
    }

    public void panduan() {
        int nowra1 = this.ra;
        String txt = this.txtGuess.getText();
        int txtint = Integer.parseInt(txt);
        if (nowra1 > txtint) {
            this.lblOutput.setText(txtint + "小了，重新输入");
        } else if (nowra1 < txtint) {
            this.lblOutput.setText(txtint + "大了，重新输入");
        } else if (nowra1 == txtint) {
            this.lblOutput.setText("猜对了第1个!");
        }

        int nowra2 = this.ra2;
        String txt2 = this.txtGuess2.getText();
        int txt2int = Integer.parseInt(txt2);
        if (nowra2 > txt2int) {
            this.lblOutput2.setText(txt2int + "小了，重新输入");
        } else if (nowra2 < txt2int) {
            this.lblOutput2.setText(txt2int + "大了，重新输入");
        } else if (nowra2 == txt2int) {
            this.lblOutput2.setText("猜对了第2个!");
        }

        int nowra3 = this.ra3;
        String txt3 = this.txtGuess3.getText();
        int txt3int = Integer.parseInt(txt3);
        if (nowra3 > txt3int) {
            this.lblOutput3.setText(txt3int + "小了，重新输入");
        } else if (nowra3 < txt3int) {
            this.lblOutput3.setText(txt3int + "大了，重新输入");
        } else if (nowra3 == txt3int) {
            this.lblOutput3.setText("猜对了第3个!!");
        }

        int nowra4 = this.ra4;
        String txt4 = this.txtGuess4.getText();
        int txt4int = Integer.parseInt(txt4);
        if (nowra4 > txt4int) {
            this.lblOutput4.setText(txt4int + "小了，重新输入");
        } else if (nowra4 < txt4int) {
            this.lblOutput4.setText(txt4int + "大了，重新输入");
        } else if (nowra4 == txt4int) {
            this.lblOutput4.setText("猜对了第4个!!");
        }

        if (nowra4 == txt4int && nowra3 == txt3int && nowra2 == txt2int && nowra1 == txtint) {
            this.lblOutput.setText("都猜对了，你太棒了！");
            this.lblOutput2.setText("都猜对了，你太棒了！");
            this.lblOutput3.setText("都猜对了，你太棒了！");
            this.lblOutput4.setText("都猜对了，你太棒了！");
            this.btnPlayAgain.setVisible(true);
        }

    }

    public NGuessNumber() {
        this.getra();
        this.setTitle("Java猜数字游戏");
        this.getContentPane().setLayout((LayoutManager) null);
        JLabel lblNewLabel = new JLabel("Java猜数字游戏");
        lblNewLabel.setFont(new Font("宋体", 1, 15));
        lblNewLabel.setHorizontalAlignment(0);
        lblNewLabel.setBounds(159, 27, 116, 18);
        this.getContentPane().add(lblNewLabel);
        JLabel lblNewLabel_1 = new JLabel("请输入4个1~10之间的数字");
        lblNewLabel_1.setHorizontalAlignment(4);
        lblNewLabel_1.setBounds(66, 72, 213, 15);
        this.getContentPane().add(lblNewLabel_1);
        this.txtGuess = new JTextField();
        this.txtGuess.setBounds(160, 99, 66, 21);
        this.getContentPane().add(this.txtGuess);
        this.txtGuess.setColumns(10);
        this.txtGuess2 = new JTextField();
        this.txtGuess2.setBounds(160, 119, 66, 21);
        this.getContentPane().add(this.txtGuess2);
        this.txtGuess2.setColumns(10);
        this.txtGuess3 = new JTextField();
        this.txtGuess3.setBounds(160, 139, 66, 21);
        this.getContentPane().add(this.txtGuess3);
        this.txtGuess3.setColumns(10);
        this.txtGuess4 = new JTextField();
        this.txtGuess4.setBounds(160, 159, 66, 21);
        this.getContentPane().add(this.txtGuess4);
        this.txtGuess4.setColumns(10);
        JButton btnNewButton = new JButton("猜一下");
        btnNewButton.setBounds(150, 185, 93, 23);
        this.getContentPane().add(btnNewButton);
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                NGuessNumber.this.panduan();
            }
        });
        this.lblOutput = new JLabel("请在输入框内输入数字并猜一下");
        this.lblOutput.setHorizontalAlignment(0);
        this.lblOutput.setBounds(51, 214, 331, 15);
        this.getContentPane().add(this.lblOutput);
        this.lblOutput2 = new JLabel("请在输入框内输入数字并猜一下");
        this.lblOutput2.setHorizontalAlignment(0);
        this.lblOutput2.setBounds(51, 234, 331, 15);
        this.getContentPane().add(this.lblOutput2);
        this.lblOutput3 = new JLabel("请在输入框内输入数字并猜一下");
        this.lblOutput3.setHorizontalAlignment(0);
        this.lblOutput3.setBounds(51, 254, 331, 15);
        this.getContentPane().add(this.lblOutput3);
        this.lblOutput4 = new JLabel("请在输入框内输入数字并猜一下");
        this.lblOutput4.setHorizontalAlignment(0);
        this.lblOutput4.setBounds(51, 274, 331, 15);
        this.getContentPane().add(this.lblOutput4);
        this.btnPlayAgain = new JButton("再玩一次");
        this.btnPlayAgain.setBounds(164, 300, 105, 23);
        this.btnPlayAgain.setVisible(true);
        this.getContentPane().add(this.btnPlayAgain);
    }

    public static void main(String[] args) {
        NGuessNumber theGame = new NGuessNumber();
        theGame.setDefaultCloseOperation(3);
        theGame.setSize(new Dimension(450, 500));
        theGame.setVisible(false);
        //重新开始不会

    }
}